package org.example.view;

import javax.swing.*;
import java.awt.*;

public class DemoH extends JFrame {
    private JTextField jtf;
    private JPasswordField jpf;
    private JTextArea jta;
    private JRadioButton jrb1, jrb2, jrb3;
    private ButtonGroup bg;
    private JComboBox<String> comboBox;

    public DemoH() throws HeadlessException {
        // 标题 一般书写在第一行
        setTitle("我的第一个界面");
        jtf = new JTextField();
        jpf = new JPasswordField();
        jta = new JTextArea();
        jrb1 = new JRadioButton("足球");
        jrb2 = new JRadioButton("篮球");
        jrb3 = new JRadioButton("排球");
        bg = new ButtonGroup();
        comboBox = new JComboBox<>(new String[]{"西安","宝鸡","商洛","渭南","汉中"});

        jtf.setBounds(10, 20, 100, 30);
        jpf.setBounds(50, 60, 100, 30);
        jta.setBounds(10, 200, 100, 100);
        jrb1.setBounds(140,20,100,30);
        jrb2.setBounds(250,20,100,30);
        jrb3.setBounds(360,20,100,30);
        comboBox.setBounds(200,200,100,30);
        bg.add(jrb1);
        bg.add(jrb2);
        bg.add(jrb3);
        add(jtf);
        add(jpf);
        add(jta);
        add(jrb1);
        add(jrb2);
        add(jrb3);
        add(comboBox);
        setLayout(null);
        // 设置尺寸和位置
        int x = 500;
        int y = 400;
        int width = 600;
        int height = 400;
        setBounds(x, y, width, height);
        // 设置窗体剧中显示
        setLocationRelativeTo(null);
        // 设置点击关闭时释放内存
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // 配置显示
        setVisible(true);
    }

    public static void main(String[] args) {
        new DemoH();
    }
}
